var guanpai = require('guanpai');

var uicreator = cc.Class({
    extends: cc.Component,

    properties: {
        screenMessagePrefab: cc.Prefab,
    },

    // use this for initialization
    onLoad: function () {
        cc.log('ui onLoad');
        guanpai.ui = this;

        // screen message
        this.showMessageList = [];
        this.screenMessageNodePool = new cc.NodePool('ScreenMessage');
    },

    createScreenMsg: function (msg) {
        if (this.screenMessageNodePool == null) {
            this.screenMessageNodePool = new cc.NodePool('ScreenMessage');
        }
        var node = this.screenMessageNodePool.get();
        if (node == null) {
            node = cc.instantiate(this.screenMessagePrefab);
        }
        cc.director.getScene().getChildByName('Canvas').addChild(node);
        node.setPosition(cc.p(0,0));
        node.opacity = 0;
        node.getChildByName("Label").getComponent(cc.Label).string = msg;
        var fadeIn = cc.fadeIn(1.0);
        var nothing = cc.moveBy(1.0, cc.p(0,0));
        var fadeOut = cc.fadeOut(1.0);
        var callFunc = cc.callFunc(()=>{
            this.screenMessageNodePool.put(node);
        });
        node.runAction(cc.sequence(fadeIn, nothing, fadeOut, callFunc));
    },

    // called every frame, uncomment this function to activate update callback
    // update: function (dt) {

    // },
});
